package com.quick.controller.system;
import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.quick.common.annotation.Log;
import com.quick.common.core.controller.BaseController;
import com.quick.common.core.domain.ApiResponse;
import com.quick.common.enums.BusinessTypeEnum;
import com.quick.system.domain.SysPost;
import com.quick.system.service.SysPostService;
import com.quick.common.utils.poi.ExcelUtil;
/**
 * 岗位信息Controller
 *
 * @Author: 吃素不吃肉
 * @Date: Tue Jul 25 14:14:44 CST 2023
 */
@Api(value = "岗位信息管理", tags = {"岗位信息操作接口"})
@RestController
@RequestMapping("/system/post")
public class SysPostController extends BaseController {
    @Autowired
    private SysPostService sysPostService;

   /**
    * 查询岗位信息列表
    */
    @PreAuthorize("@ps.hasPermission('system:post:list')" )
    @GetMapping("/list")
    @ApiOperation(value = "分页查询岗位信息列表")
    public ApiResponse list(SysPost sysPost) {
        try {
            startPage();
            List<SysPost> list = sysPostService.selectSysPostList(sysPost);
            return paging(list);
        } finally {
            clearPage();
        }

    }

    /**
     * 导出岗位信息列表
     */
    @PreAuthorize("@ps.hasPermission('system:post:export')" )
    @Log(title = "岗位信息", businessType = BusinessTypeEnum.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出岗位信息列表")
    public void export(HttpServletResponse response, SysPost sysPost) {
        List<SysPost> list = sysPostService.selectSysPostList(sysPost);
        ExcelUtil<SysPost> util = new ExcelUtil<>(SysPost.class);
        util.exportExcel(response, list, "岗位信息数据");
    }

    /**
     * 获取岗位信息详细信息
     */
    @PreAuthorize("@ps.hasPermission('system:post:query')")
    @GetMapping(value = "/{postId}")
    @ApiOperation(value = "获取岗位信息详细信息")
    public ApiResponse getInfo(@PathVariable("postId") Long postId) {
        return success(sysPostService.selectSysPostByPostId(postId));
    }

    /**
     * 新增岗位信息
     */
    @PreAuthorize("@ps.hasPermission('system:post:add')")
    @Log(title = "岗位信息", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation(value = "新增岗位信息")
    public ApiResponse add(@RequestBody SysPost sysPost) {
        return success(sysPostService.insertSysPost(sysPost));
    }

    /**
     * 修改岗位信息
     */
    @PreAuthorize("@ps.hasPermission('system:post:edit')")
    @Log(title = "岗位信息", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改岗位信息")
    public ApiResponse edit(@RequestBody SysPost sysPost) {
        return success(sysPostService.updateSysPost(sysPost));
    }

    /**
     * 删除岗位信息
     */
    @PreAuthorize("@ps.hasPermission('system:post:remove')")
    @Log(title = "岗位信息", businessType = BusinessTypeEnum.DELETE)
    @DeleteMapping("/{postIds}")
    @ApiOperation(value = "删除岗位信息")
    public ApiResponse remove(@PathVariable Long[] postIds) {
        return success(sysPostService.deleteSysPostByPostIds(postIds));
    }
}
